package com.gxa.eshops.portal.config;

import com.gxa.eshops.portal.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Nonnull;

/**
 * @program: IntelliJ IDEA
 * @description:
 * @author: Mr.Wang
 * @create: 2022-07-07 11:35
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    TokenInterceptor tokenInterceptor;
    //注册拦截器,调用addInterceptors

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                //拦截的请求
                .addPathPatterns("/**/**")
                //直接放行的请求
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v3/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/doc.html/**")
                .excludePathPatterns("/**/login")
                .excludePathPatterns("/**/register");
    }

    @Override
    public void addResourceHandlers(@Nonnull ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/getImg").addResourceLocations("https://wangpeng-1312542869.cos.ap-chengdu.myqcloud.com/headImg/");
    }
}
